package kuang.juc.lock8;

import java.util.concurrent.TimeUnit;


/**
 * synchronized锁类的调用者
 * 此时两个方法是一把锁
 * 先发短信，后打电话
 */
public class Test1 {
    public static void main(String[] args) {
        Phone phone = new Phone();

        new Thread(phone::sedMsg,"A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(phone::call,"B").start();
    }
}

class Phone{
    public synchronized void sedMsg() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");
    }

    public synchronized void call(){
        System.out.println("打电话");
    }
}
